package com.cy.aircompressor.api;

import androidx.lifecycle.MutableLiveData;

import com.cy.aircompressor.entity.component.Component;
import com.cy.aircompressor.entity.compressor.Compressor;
import com.cy.aircompressor.entity.maintenance.MaintenanceRecord;
import com.cy.aircompressor.entity.power.PowerStation;
import com.cy.aircompressor.entity.select.SelectDict;
import com.cy.aircompressor.entity.sensor.Sensor;
import com.cy.aircompressor.entity.sensor.SensorLatestData;
import com.cy.aircompressor.entity.sensor.SensorStatisticsData;
import com.cy.aircompressor.entity.system.SysConfig;
import com.cy.aircompressor.entity.system.UserInfo;
import com.cy.aircompressor.entity.warning.WarningConfig;
import com.cy.aircompressor.entity.warning.WarningMsg;
import com.drug.lib.view.recycptr.bean.RowEntity;
import com.net.model.base.Resource;
import com.net.model.model.BaseModel;

import java.util.List;
import java.util.Map;

/**
 * @author zhouhequan
 * 版本：1.0
 * 创建日期：2021/11/13 or 13:37
 * 描述：---
 */
public class RepositoryImpl extends BaseModel {
    public static RepositoryImpl get() {
        return new RepositoryImpl();
    }


    /*************************用户相关***start****************************************/


    public MutableLiveData<Resource<String>> login(Map<String, Object> body) {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.login(body));
    }
    public MutableLiveData<Resource<Object>> logout() {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.logout());
    }

    public MutableLiveData<Resource<Object>> addUser(Object object) {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.addUser(object));
    }

    public MutableLiveData<Resource<Object>> updatePwd(Object object) {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.updatePwd(object));
    }

    public MutableLiveData<Resource<Object>> updateUser(Object object) {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.updateUser(object));
    }

    public MutableLiveData<Resource<Object>> deleteByIds(String[] ids) {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.deleteByIds(ids));
    }

    public MutableLiveData<Resource<UserInfo>> currentUserInfo() {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.currentUserInfo());
    }

    public MutableLiveData<Resource<UserInfo>> queryUserInfoById(String id) {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.queryById(id));
    }

    public MutableLiveData<Resource<RowEntity<UserInfo>>> queryUserInfoByPage(Integer pageNum, Integer pageSize, String account, String name,
                                                                              String powerStationId) {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.getUserByPage(pageNum, pageSize, account, name, powerStationId));
    }

    public MutableLiveData<Resource<SysConfig>> queryConfig() {
        UserApi userApi = getApiService(UserApi.class);
        return requestNew(userApi.queryConfig());
    }

    /*************************用户相关***end****************************************/


    /*************************空压机相关***start****************************************/
    public MutableLiveData<Resource<List<SensorLatestData>>> queryCompressorSensorData(List<String> pram) {
        AirApi airApi = getApiService(AirApi.class);
        return requestNew(airApi.queryCompressorSensorData(pram));
    }

    public MutableLiveData<Resource<RowEntity<Compressor>>> compressor(Integer pageNum, String powerStationId, String sn) {
        AirApi airApi = getApiService(AirApi.class);
        return requestNew(airApi.compressor(pageNum, 50, powerStationId, sn));
    }

    public MutableLiveData<Resource<RowEntity<Compressor>>> compressor(Integer pageNum, Integer pageSize, String powerStationId, String sn) {
        AirApi airApi = getApiService(AirApi.class);
        return requestNew(airApi.compressor(pageNum, pageSize, powerStationId, sn));
    }
    /*************************空压机相关***end****************************************/


    /*************************告警相关***start****************************************/
    public MutableLiveData<Resource<Integer>> queryWarningCount() {
        WarningApi warningApi = getApiService(WarningApi.class);
        return requestNew(warningApi.queryWarningCount(null, null, null, null,
                null, null, null, null, null));
    }


    public MutableLiveData<Resource<RowEntity<WarningMsg>>> queryWarningByPage(String compressorId) {
        return queryWarningByPage(1, 3, compressorId, null, null,
                null, null, null, null, null, null);
    }

    public MutableLiveData<Resource<RowEntity<WarningMsg>>> queryWarningByPage(Integer pageNum, Integer pageSize, String compressorId) {
        return queryWarningByPage(pageNum, pageSize, compressorId, null, null,
                null, null, null, null, null, null);
    }

    public MutableLiveData<Resource<RowEntity<WarningMsg>>> queryWarningByPage(Integer pageNum, Integer pageSize,
                                                                               String compressorId, String compressorModel,
                                                                               String compressorPartCode, String compressorPointCode,
                                                                               String endTime, String sensorId, Integer sensorType,
                                                                               String startTime, Integer status) {
        WarningApi warningApi = getApiService(WarningApi.class);
        return requestNew(warningApi.queryWarningByPage(pageNum, pageSize, compressorId, compressorModel, compressorPartCode, compressorPointCode, endTime, sensorId, sensorType, startTime, status));
    }

    public MutableLiveData<Resource<Object>> batchUpdateWarningConfig(List<Object> parameters) {
        WarningApi warningApi = getApiService(WarningApi.class);
        return requestNew(warningApi.batchUpdate(parameters));
    }

    public MutableLiveData<Resource<Object>> batchAddWarningConfig(List<Object> object) {
        WarningApi warningApi = getApiService(WarningApi.class);
        return requestNew(warningApi.batchAdd(object));
    }
    public MutableLiveData<Resource<Object>> updateStatus(String id) {
        WarningApi warningApi = getApiService(WarningApi.class);
        return requestNew(warningApi.updateStatus(id));
    }


    public MutableLiveData<Resource<Object>> addWarningConfig(Object object) {
        WarningApi warningApi = getApiService(WarningApi.class);
        return requestNew(warningApi.add(object));
    }

    public MutableLiveData<Resource<Object>> updateWarningConfig(Object object) {
        WarningApi warningApi = getApiService(WarningApi.class);
        return requestNew(warningApi.update(object));
    }

    public MutableLiveData<Resource<RowEntity<WarningConfig>>> queryWarningConfigByPage(Integer pageNum, Integer pageSize, String compressorModel,
                                                                                  String compressorPartCode, String compressorPointCode, Integer sensorType, Integer status) {
        WarningApi warningApi = getApiService(WarningApi.class);
        return requestNew(warningApi.queryWarningConfigByPage(pageNum, pageSize, compressorModel, compressorPartCode, compressorPointCode, sensorType, status));
    }
    /*************************告警相关***end****************************************/


    /*************************配置相关***start****************************************/

    public MutableLiveData<Resource<List<SelectDict>>> compressorPart() {
        SelectApi selectApi = getApiService(SelectApi.class);
        return requestNew(selectApi.compressorPart());
    }

    public MutableLiveData<Resource<List<SelectDict>>> compressorPoint() {
        SelectApi selectApi = getApiService(SelectApi.class);
        return requestNew(selectApi.compressorPoint());
    }

    public MutableLiveData<Resource<List<SelectDict>>> compressor() {
        SelectApi selectApi = getApiService(SelectApi.class);
        return requestNew(selectApi.compressor());
    }

    public MutableLiveData<Resource<List<SelectDict>>> collectorChannel() {
        SelectApi selectApi = getApiService(SelectApi.class);
        return requestNew(selectApi.collectorChannel());
    }

    public MutableLiveData<Resource<List<SelectDict>>> powerStation() {
        SelectApi selectApi = getApiService(SelectApi.class);
        return requestNew(selectApi.powerStation());
    }

    public MutableLiveData<Resource<List<SelectDict>>> sensorRange() {
        SelectApi selectApi = getApiService(SelectApi.class);
        return requestNew(selectApi.sensorRange());
    }

    public MutableLiveData<Resource<List<SelectDict>>> sensorType() {
        SelectApi selectApi = getApiService(SelectApi.class);
        return requestNew(selectApi.sensorType());
    }
    /*************************配置相关***end****************************************/


    /*************************维保相关***start****************************************/

    public MutableLiveData<Resource<RowEntity<MaintenanceRecord>>> queryMaintenanceRecordByPage(Integer pageNum, Integer pageSize, String compressorId, String powerStationId) {
        MaintenanceApi maintenanceApi = getApiService(MaintenanceApi.class);
        return requestNew(maintenanceApi.queryMaintenanceRecordByPage(pageNum, pageSize, compressorId, powerStationId));
    }

    public MutableLiveData<Resource<MaintenanceRecord>> queryMaintenanceRecordById(String id) {
        MaintenanceApi maintenanceApi = getApiService(MaintenanceApi.class);
        return requestNew(maintenanceApi.queryMaintenanceRecordById(id));
    }

    public MutableLiveData<Resource<Object>> addMaintenanceRecord(Object o) {
        MaintenanceApi maintenanceApi = getApiService(MaintenanceApi.class);
        return requestNew(maintenanceApi.addMaintenanceRecord(o));
    }

    /*************************维保相关***end****************************************/


    /*************************传感器相关***start****************************************/
    public MutableLiveData<Resource<List<SensorStatisticsData>>> querySensorStatisticsData(String startTime, String endTime,
                                                                                           String sortOrder, String sn, Integer type) {
        SensorApi sensorApi = getApiService(SensorApi.class);
        return requestNew(sensorApi.querySensorStatisticsData(startTime, endTime, sortOrder, sn, type));
    }

    public MutableLiveData<Resource<RowEntity<Sensor>>> querySensorByPage(Integer pageNum, Integer pageSize, String compressorId, String powerStationId,
                                                                          String compressorPartCode, String sn, Integer type) {
        SensorApi sensorApi = getApiService(SensorApi.class);
        return requestNew(sensorApi.querySensorByPage(pageNum, pageSize, compressorId, powerStationId, compressorPartCode, sn, type));
    }

    /*************************传感器相关***end****************************************/


    public MutableLiveData<Resource<RowEntity<Component>>> queryComponentByPage(Integer pageNum, Integer pageSize, String compressorId, String powerStationId, String compressorPartCode, String sn) {
        ComponentApi componentApi = getApiService(ComponentApi.class);
        return requestNew(componentApi.queryComponentByPage(pageNum, pageSize, compressorId, powerStationId, compressorPartCode, sn));
    }


    /*************************电站相关***start****************************************/

    public MutableLiveData<Resource<Object>> addPowerStation(Object object) {
        PowerStationApi powerStationApi = getApiService(PowerStationApi.class);
        return requestNew(powerStationApi.addPowerStation(object));
    }


    public MutableLiveData<Resource<Object>> updatePowerStation(Object object) {
        PowerStationApi powerStationApi = getApiService(PowerStationApi.class);
        return requestNew(powerStationApi.updatePowerStation(object));
    }

    public MutableLiveData<Resource<Object>> deletePowerStationByIds(String[] ids) {
        PowerStationApi powerStationApi = getApiService(PowerStationApi.class);
        return requestNew(powerStationApi.deleteByIds(ids));
    }


    public MutableLiveData<Resource<PowerStation>> queryPowerStationById(String id) {
        PowerStationApi powerStationApi = getApiService(PowerStationApi.class);
        return requestNew(powerStationApi.queryPowerStationById(id));
    }

    public MutableLiveData<Resource<RowEntity<PowerStation>>> queryPowerStationByPage(Integer pageNum, Integer pageSize, String name) {
        PowerStationApi powerStationApi = getApiService(PowerStationApi.class);
        return requestNew(powerStationApi.getPowerStationByPage(pageNum, pageSize, name));
    }
    /*************************电站相关***end****************************************/

}
